<div class="crumb-wrap">
    <div class="crumb-list"> <i class="icon-font"></i>
        <a href="<?=site_url()?>">首页</a>
        <span class="crumb-step">&gt;</span>
        <span class="crumb-name">用户管理</span>
    </div>
</div>
<div class="search-wrap">
    <div class="search-content">
        <form action="<?=site_url('users/index')?>" method="get">
            <table class="search-tab">
                <tr>
                    <th width="120">权限:</th>
                    <td>
                        <select name="group" id="">
                            <option value="">全部</option>
                            <option value="admin" <?=!empty($_GET['group'])&&$_GET['group'] == 'admin' ? 'selected' : ''?>>管理员</option>
                            <?php foreach($group_list as $k => $v):?>
                            <option value="<?=$v['id']?>" <?=!empty($_GET['group'])&&$_GET['group'] == $v['id'] ? 'selected' : ''?>><?=$v['title']?></option>
                            <?php endforeach;?>
                        </select>
                    </td>
                    <th width="70">关键字:</th>
                    <td>
                        <input class="common-text" placeholder="请输入用户名称或者登录帐号" name="keywords" value="<?=empty($_GET['keywords']) ? '' : $_GET['keywords']?>" id="" type="text"></td>
                    <td>
                        <input class="btn btn-primary btn2" value="查询" type="submit"></td>
                    <td><a href="<?=site_url('users/index')?>" class="btn btn-primary btn2">重置</a></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div class="result-wrap">
    <form name="myform" id="myform" method="post">
        <div class="result-title">
            <div class="result-list">
                <a href="<?=site_url('users/create')?>"> <i class="icon-font"></i>
                    新增用户
                </a>
            </div>
        </div>
        <div class="result-content">
            <table class="result-tab" width="100%">
                <tr>
                    <th>ID</th>
                    <th>登录帐号</th>
                    <th>姓名</th>
                    <th>联系电话</th>
                    <th>联系邮箱</th>
                    <th>用户余额</th>
                    <th>最后登录时间</th>
                    <th>特权</th>
                    <th>上级用户</th>
                    <th>操作</th>
                </tr>
                <?php foreach($list as $k => $v):?>

                <tr>
                    <td><?=$v['id']?></td>
                    <td><?=$v['username']?></td>
                    <td><?=$v['name']?></td>
                    <td><?=$v['phone']?></td>
                    <td><?=$v['email']?></td>
                    <td style="color:<?=$v['money'] > 0 ? 'green' : 'red'?>"><?=$v['status'] == 3 ? $v['money'] : '------'?></td>
                    <td><?=date('Y-m-d H:i:s',$v['login_time'])?></td>
                    <td style="color:<?=$v['status'] == 3 ? 'green' : 'red'?>"><?=$v['group']?></td>
                    <?php if($v['puser']['id'] == 0):?>
                        <td><?=$v['puser']['username']?></td>
                    <?php else:?>
                        <td>
                            <a href="<?=site_url('users/index?keywords='.$v['puser']['username'])?>"><?=$v['puser']['username']?></a>
                            &nbsp;&nbsp;
                            <?php if($v['puser']['pid'] > 0):?>
                                <a href="<?=site_url('users/from?uid='.$v['id'])?>" title="用户所有上级">更多</a>
                            <?php endif;?>
                        </td>
                    <?php endif;?>
                    <td>
                        <?php if($v['status'] == 3):?>
                        <a class="link-update" href="javascript:;" onclick="set_bill(<?=$v['id']?>)">充值</a>
                        <a class="link-update" href="javascript:;" onclick="show_bill('<?=site_url('bill/show_bill?uid='.$v['id'])?>')">账单</a>
                        <?php endif;?>
                        <a class="link-update" href="<?=site_url('users/update?uid='.$v['id'])?>">修改</a>
                        <?php if($v['status'] != 1):?>
                        <a class="link-del" href="<?=site_url('users/reset_pwd?uid='.$v['id'])?>">重置密码</a>
                        <a class="link-del" href="javascript:;" onclick="user_delete(<?=$v['id']?>)">删除</a>
                        <?php endif;?>

                    </td>
                </tr>
                <?php endforeach;?>
            </table>
            <div class="list-page"><?=$page?></div>
        </div>
    </form>
</div>

<script type="text/javascript">
    layer.config({
        extend: 'extend/layer.ext.js'
    });
    function user_delete(uid){
        layer.confirm('删除之后不可恢复，是否确定？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.post("<?=site_url('users/delete')?>",{uid:uid},function(data){
                if(data == 1){
                    layer.alert("操作成功！",{
                        icon:1,
                    },function(){
                        location.reload();
                    });
                }else{
                    layer.alert(data,{
                        icon:2,
                    });
                }
            });
        });
    }

    /**
     * 查看账单
     */
    function show_bill(url){
        layer.open({
            type: 2,
            title:"用户账单",
            area: ['800px', '600px'],
            fix: false, //不固定
            maxmin: true,
            content: url
        });
    }

    /**
     * 充值
     */
    function set_bill(uid){
        layer.prompt({
            title: '输入充值金额，并确定',
            formType: 0 //prompt风格，支持0-2
        }, function(money){
            layer.confirm('为该用户充值"'+money+'"，是否确定？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.post("<?=site_url('bill/recharge')?>",{uid:uid,money:money},function(data){
                    if(data == 1){
                        layer.alert("操作成功！",{
                            icon:1,
                        },function(){
                            location.reload();
                        });
                    }else{
                        layer.alert(data,{
                            icon:2,
                        });
                    }
                });
            });
        });
    }
</script>